package com.project.server.garden;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.garden.TGardenGuard;
import com.project.server.service.garden.ITGardenGuardService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 园区门禁信息Controller
 *
 * @author project
 * @date 2021-07-01
 */
@RestController
@RequestMapping("/server/guard")
public class TGardenGuardController extends BaseController {

    @Resource
    private ITGardenGuardService tGardenGuardService;

    /**
     * 查询园区门禁信息列表
     */
    @PreAuthorize("@ss.hasPermi('server:guard:list')")
    @GetMapping("/list")
    public TableDataInfo list(TGardenGuard tGardenGuard) {
        startPage();
        List<TGardenGuard> list = tGardenGuardService.selectTGardenGuardList(tGardenGuard);
        return getDataTable(list);
    }


    /**
     * 导出园区门禁信息列表
     */
    @PreAuthorize("@ss.hasPermi('server:guard:export')")
    @Log(title = "园区门禁信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TGardenGuard tGardenGuard) {
        List<TGardenGuard> list = tGardenGuardService.selectTGardenGuardList(tGardenGuard);
        ExcelUtil<TGardenGuard> util = new ExcelUtil<TGardenGuard>(TGardenGuard.class);
        return util.exportExcel(list, "园区门禁信息列表");
    }

    /**
     * 获取园区门禁信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:guard:query')")
    @GetMapping(value = "/{guardId}")
    public AjaxResult getInfo(@PathVariable("guardId") Long guardId) {
        return AjaxResult.success(tGardenGuardService.selectTGardenGuardById(guardId));
    }

    /**
     * 新增园区门禁信息
     */
    @PreAuthorize("@ss.hasPermi('server:guard:add')")
    @Log(title = "园区门禁信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TGardenGuard tGardenGuard) {
        return toAjax(tGardenGuardService.insertTGardenGuard(tGardenGuard));
    }

    /**
     * 修改园区门禁信息
     */
    @PreAuthorize("@ss.hasPermi('server:guard:edit')")
    @Log(title = "园区门禁信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TGardenGuard tGardenGuard) {
        return toAjax(tGardenGuardService.updateTGardenGuard(tGardenGuard));
    }

    /**
     * 删除园区门禁信息
     */
    @PreAuthorize("@ss.hasPermi('server:guard:remove')")
    @Log(title = "园区门禁信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{guardIds}")
    public AjaxResult remove(@PathVariable Long[] guardIds) {
        return toAjax(tGardenGuardService.deleteTGardenGuardByIds(guardIds));
    }
}
